package com.gxa.retail_admin.aspect;

import com.gxa.common.utils.IpUtils;
import com.gxa.modules.mapper.LogMapper;
import com.gxa.modules.pojo.Sys_Login_Log;
import com.gxa.retail_admin.controller.UserController;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@Service
//操作日志切面类
@Aspect
@Component
public class LoginLogAspect {
    @Autowired(required = false)
    private LogMapper logMapper;
//    private Object request;


    @After("execution(* com.gxa.retail_admin.controller.UserController.login(..))")
    public  void afterPrintLoginLog(){
//        String Ip = IpUtils.getIpAddr((HttpServletRequest) request);
        Sys_Login_Log sys_login_log = new Sys_Login_Log();
        sys_login_log.setLogin_oi("管理员登录");
        sys_login_log.setType(1);

        sys_login_log.setIpaddr("接收登录IP"+"192.336.2.221");
        sys_login_log.setClazz("com.gxa.retail_admin.controller.UserController.login");
        sys_login_log.setMethod("login");
        sys_login_log.setMadel("暂无数据");
        sys_login_log.setRecord_id(0);
        sys_login_log.setCreate_date(new Date());
        sys_login_log.setOper_name("admin");
        logMapper.insertLoginLogMap(sys_login_log);
        System.out.println("==登录成功=="+new Date().toLocaleString());
    }
}
